package com.fqy.ticket.generator.enums;
/*
* 严格依赖枚举的声明顺序，如，INT在前BIGINT的类型会被匹配为Integer而不是Long
*/
public enum SqlType {
    VARCHAR("String"),
    CHAR("String"),
    TEXT("String"),
    DATETIME("Date"),
    TIME("Date"),
    DATE("Date"),
    BIGINT("Long"),
    INT("Integer"),
    LONG("Long"),
    DECIMAL("BigDecimal"),
    BOOLEAN("Boolean");

    private final String javaType;
    SqlType(String javaType) {
        this.javaType = javaType;
    }

    public static String map(String sqlType) {
        if (sqlType==null) {
            return "String";
        }
        String upper = sqlType.toUpperCase();
        for (SqlType type : SqlType.values()) {
            if (upper.contains(type.name())) {
                System.out.printf("map %s to %s%n", sqlType, type.javaType);
                return type.javaType;
            }
        }
        return "String";
    }
}
